import Vue from "vue";
import Router from "vue-router";
import Layout from "@/layout";
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path*",
        component: () => import("@/views/redirect/index")
      }
    ]
  },
  {
    path: "/",
    component: Layout,
    redirect: "dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard"),
        name: "dashboard",
        meta: {
          title: "控制台主页",
          icon: "icon-dashboard",
          affix: true
        }
      },
      {
        path: "/userCenter",
        component: () => import("@/views/cm-system/userCenter"),
        hidden: true,
        name: "usercenter",
        meta: {
            title: "个人中心",
            icon: "icon-dashboard",
        }
      },
    ]
  }
];
const modulesFiles = require.context("./modules", false, /\.js$/); // 导入整体模块 无需额外引入
modulesFiles.keys().map(path => {
  // 兼容处理：.default 获取 ES6 规范暴露的内容; 后者获取 commonJS 规范暴露的内容
  //constantRoutes.push(modulesFiles(path).default || modulesFiles(path));
});
Vue.use(Router);

// let base = `${process.env.BASE_URL}` // 动态获取二级目录
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    // base: base,
    scrollBehavior: () => ({
      y: 0
    }),
    routes: constantRoutes
  });

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher;
}

const router = createRouter();
export default router;
